package com.zhangtao.demo.common.vo;

import com.zhangtao.demo.common.dto.WebSocketCommand;
import com.zhangtao.demo.common.enums.ResultStatus;

import java.util.List;
import java.util.StringJoiner;

public class ResponseResult<T> {
    private Long requestTime;
    private String commandName;
    private String code;
    private T data;
    private List<T> datas;
    private String errorCode;
    private String errorMessage;
    private String message;

    public ResponseResult(WebSocketCommand wsc, T data) {
        this.requestTime = wsc.getRequestTime();
        this.commandName = wsc.getCommand();
        this.data = data;
        this.code = ResultStatus.SUCCESS.getCode();
        this.message = ResultStatus.SUCCESS.getDescription();
    }
    public ResponseResult(T data) {
        this.data = data;
        this.code = ResultStatus.SUCCESS.getCode();
        this.message = ResultStatus.SUCCESS.getDescription();
    }
    public ResponseResult(ResultStatus rs) {
        this.code = ResultStatus.FAILED.getCode();
        this.message = ResultStatus.FAILED.getDescription();
        this.errorCode = rs.getCode();
        this.errorMessage = rs.getDescription();
    }
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public List<T> getDatas() {
        return datas;
    }

    public void setDatas(List<T> datas) {
        this.datas = datas;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Long getRequestTime() {
        return requestTime;
    }

    public void setRequestTime(Long requestTime) {
        this.requestTime = requestTime;
    }

    public String getCommandName() {
        return commandName;
    }

    public void setCommandName(String commandName) {
        this.commandName = commandName;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", "{", "}")
                .add("requestTime:" + requestTime + "")
                .add("commandName:'" + commandName + "'")
                .add("code:'" + code + "'")
                .add("data:" + data)
                .add("datas:" + datas)
                .add("errorCode:'" + errorCode + "'")
                .add("errorMessage:'" + errorMessage + "'")
                .add("message:'" + message + "'")
                .toString();
    }
}
